00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <errno.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <sys/ioctl.h>
00014 #include <sys/socket.h>
00015 #include <netinet/in.h>
00016
00017 #include <net/gen/in.h>
00018 #include <net/gen/tcp.h>
00019 #include <net/gen/tcp_io.h>
00020 #include <net/gen/udp.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 int getsockname(int fd, struct sockaddr *_RESTRICT address,
00031 socklen_t *_RESTRICT address_len)
00032 {
00033 nwio_tcpconf_t tcpconf;
00034 socklen_t len;
00035 struct sockaddr_in sin;
00036
00037 #ifdef DEBUG
00038 fprintf(stderr,"mnx_getsockname: ioctl fd %d.\n", fd);
00039 #endif
00040 if (ioctl(fd, NWIOGTCPCONF, &tcpconf)==-1) {
00041 #ifdef DEBUG
00042 fprintf(stderr,"mnx_getsockname: error %d\n", errno);
00043 #endif
00044 return (-1);
00045 }
00046 #ifdef DEBUG1
00047 fprintf(stderr, "mnx_getsockname: from %s, %u",
00048 inet_ntoa(tcpconf.nwtc_remaddr),
00049 ntohs(tcpconf.nwtc_remport));
00050 fprintf(stderr," for %s, %u\n",
00051 inet_ntoa(tcpconf.nwtc_locaddr),
00052 ntohs(tcpconf.nwtc_locport));
00053 #endif
00054
00055
00056
00057
00058 memset(&sin, '\0', sizeof(sin));
00059 sin.sin_family= AF_INET;
00060 sin.sin_addr.s_addr= tcpconf.nwtc_locaddr ;
00061 sin.sin_port= tcpconf.nwtc_locport;
00062
00063 len= *address_len;
00064 if (len > sizeof(sin))
00065 len= sizeof(sin);
00066 memcpy(address, &sin, len);
00067 *address_len= len;
00068
00069 return 0;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078