libowfat/socket/socket_bind4.c
leitner 1217583e2b now that gcc 11's static analyzer looks at array bounds in arguments
like "char ip[4]", let's be more strict about that
2021-04-27 17:39:42 +00:00

23 lines
541 B
C

#ifndef __MINGW32__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "uint16.h"
#include "uint32.h"
#include "socket.h"
int socket_bind4(int s,const char ip[4],uint16 port) {
struct sockaddr_in si;
byte_zero(&si,sizeof si);
si.sin_family = AF_INET;
uint16_pack_big((char*) &si.sin_port,port);
if (ip)
*(uint32*)&si.sin_addr = *(uint32*)ip;
else
si.sin_addr.s_addr=INADDR_ANY;
return winsock2errno(bind(s,(struct sockaddr*)&si,sizeof si));
}