1 | /*
|
---|
2 |
|
---|
3 | getsockname()
|
---|
4 |
|
---|
5 | from socket emulation library for Minix 2.0.x
|
---|
6 |
|
---|
7 | */
|
---|
8 |
|
---|
9 |
|
---|
10 | #include <errno.h>
|
---|
11 | #include <stdio.h>
|
---|
12 | #include <string.h>
|
---|
13 | #include <sys/ioctl.h>
|
---|
14 | #include <sys/socket.h>
|
---|
15 | #include <netinet/in.h>
|
---|
16 |
|
---|
17 | #include <net/gen/in.h>
|
---|
18 | #include <net/gen/tcp.h>
|
---|
19 | #include <net/gen/tcp_io.h>
|
---|
20 | #include <net/gen/udp.h>
|
---|
21 | #include <net/gen/udp_io.h>
|
---|
22 |
|
---|
23 |
|
---|
24 | /*
|
---|
25 | #define DEBUG 0
|
---|
26 | */
|
---|
27 |
|
---|
28 | /*
|
---|
29 | getsockname...
|
---|
30 | */
|
---|
31 | int getsockname(int fd, struct sockaddr *_RESTRICT address,
|
---|
32 | socklen_t *_RESTRICT address_len)
|
---|
33 | {
|
---|
34 | nwio_tcpconf_t tcpconf;
|
---|
35 | socklen_t len;
|
---|
36 | struct sockaddr_in sin;
|
---|
37 |
|
---|
38 | #ifdef DEBUG
|
---|
39 | fprintf(stderr,"mnx_getsockname: ioctl fd %d.\n", fd);
|
---|
40 | #endif
|
---|
41 | if (ioctl(fd, NWIOGTCPCONF, &tcpconf)==-1) {
|
---|
42 | #ifdef DEBUG
|
---|
43 | fprintf(stderr,"mnx_getsockname: error %d\n", errno);
|
---|
44 | #endif
|
---|
45 | return (-1);
|
---|
46 | }
|
---|
47 | #ifdef DEBUG1
|
---|
48 | fprintf(stderr, "mnx_getsockname: from %s, %u",
|
---|
49 | inet_ntoa(tcpconf.nwtc_remaddr),
|
---|
50 | ntohs(tcpconf.nwtc_remport));
|
---|
51 | fprintf(stderr," for %s, %u\n",
|
---|
52 | inet_ntoa(tcpconf.nwtc_locaddr),
|
---|
53 | ntohs(tcpconf.nwtc_locport));
|
---|
54 | #endif
|
---|
55 | /*
|
---|
56 | addr->sin_addr.s_addr = tcpconf.nwtc_remaddr ;
|
---|
57 | addr->sin_port = tcpconf.nwtc_locport;
|
---|
58 | */
|
---|
59 | memset(&sin, '\0', sizeof(sin));
|
---|
60 | sin.sin_family= AF_INET;
|
---|
61 | sin.sin_addr.s_addr= tcpconf.nwtc_locaddr ;
|
---|
62 | sin.sin_port= tcpconf.nwtc_locport;
|
---|
63 |
|
---|
64 | len= *address_len;
|
---|
65 | if (len > sizeof(sin))
|
---|
66 | len= sizeof(sin);
|
---|
67 | memcpy(address, &sin, len);
|
---|
68 | *address_len= len;
|
---|
69 |
|
---|
70 | return 0;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|