. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / ip / getsockname.c
blob5928e6399c8825429ca584b5036e804518a7a045
1 /*
3 getsockname()
5 from socket emulation library for Minix 2.0.x
7 */
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>
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>
25 #define DEBUG 0
29 getsockname...
31 int getsockname(int fd, struct sockaddr *_RESTRICT address,
32 socklen_t *_RESTRICT address_len)
34 nwio_tcpconf_t tcpconf;
35 socklen_t len;
36 struct sockaddr_in sin;
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);
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
56 addr->sin_addr.s_addr = tcpconf.nwtc_remaddr ;
57 addr->sin_port = tcpconf.nwtc_locport;
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;
64 len= *address_len;
65 if (len > sizeof(sin))
66 len= sizeof(sin);
67 memcpy(address, &sin, len);
68 *address_len= len;
70 return 0;