1
/* ========================================================================
2
* Copyright 1988-2006 University of Washington
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
11
* ========================================================================
15
* Program: Operating-system dependent routines -- PTX version
17
* Author: Mark Crispin
18
* Networks and Distributed Computing
19
* Computing & Communications
20
* University of Washington
21
* Administration Building, AG-44
23
* Internet: MRC@CAC.Washington.EDU
26
* Last Edited: 7 December 2006
29
#include "tcp_unix.h" /* must be before osdep includes tcp.h */
36
#include <sys/tiuser.h>
37
#include <sys/stropts.h>
38
#include <sys/socket.h>
40
#include <netinet/in.h>
41
#include <arpa/inet.h>
46
#include <sys/select.h>
50
extern char *sys_errlist[];
52
#define DIR_SIZE(d) d->d_reclen
54
#define toint(c) ((c)-'0')
55
#define isodigit(c) (((unsigned)(c)>=060)&((unsigned)(c)<=067))
62
#define env_init ENV_INIT
65
#define getpeername Getpeername
73
/* Jacket around env_init() to work around PTX inetd braindamage */
75
static char may_need_server_init = T;
77
long env_init (char *user,char *home)
79
if (may_need_server_init) { /* maybe need to do server init cruft? */
80
may_need_server_init = NIL; /* not any more we don't */
81
if (!getuid ()) { /* if root, we're most likely a server */
82
t_sync (0); /* PTX inetd is stupid, stupid, stupid */
83
ioctl (0,I_PUSH,"tirdwr");/* it needs this cruft, else servers won't */
84
dup2 (0,1); /* work. How obnoxious!!! */
87
ENV_INIT (user,home); /* call the real routine */
90
/* Emulator for BSD gethostid() call
91
* Returns: unique identifier for this machine
96
struct sockaddr_in sin;
97
int inet = t_open (TLI_TCP, O_RDWR, 0);
98
if (inet < 0) return 0;
99
getmyinaddr (inet,&sin,sizeof (sin));
101
return sin.sin_addr.s_addr;
105
/* Replaced version of getpeername() that jackets into getpeerinaddr()
106
* Accepts: file descriptor
107
* pointer to Internet socket addr
109
* Returns: zero if success, data in socket addr
112
int Getpeername (int s,struct sockaddr *name,int *namelen)
114
return getpeerinaddr (s,(struct sockaddr_in *) name,*namelen);