blob: 7ad6dcf549338e07015c79be06479bf23f6af92e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "socket.h"
#include "uint16.h"
int socket_local4(int s,char ip[4],u16 *port)
{
struct sockaddr_in sa;
unsigned int dummy = sizeof sa;
if (getsockname(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
memcpy(ip,(char *) &sa.sin_addr,4);
u16_unpack_big((char *) &sa.sin_port,port);
return 0;
}
|