diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
commit | 6c027b4de25a529908be895e7ff19236f4002a57 (patch) | |
tree | f70d3a400bbb9ba8a83e9d4ffcaa4b6e367fc8bb /socket_conn.c | |
download | crypto-6c027b4de25a529908be895e7ff19236f4002a57.zip crypto-6c027b4de25a529908be895e7ff19236f4002a57.tar.gz |
initial commit, resurrect one of my realy old projects
Diffstat (limited to 'socket_conn.c')
-rw-r--r-- | socket_conn.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/socket_conn.c b/socket_conn.c new file mode 100644 index 0000000..0d3b7f9 --- /dev/null +++ b/socket_conn.c @@ -0,0 +1,35 @@ +#include <string.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <unistd.h> +#include "socket.h" +#include "uint16.h" + + +int socket_connect4(int s,const char ip[4],u16 port) +{ + struct sockaddr_in sa; + + memset(&sa,0,sizeof sa); + sa.sin_family = AF_INET; + u16_pack_big((char *) &sa.sin_port,port); + memcpy((char *) &sa.sin_addr,ip,4); + + return connect(s,(struct sockaddr *) &sa,sizeof sa); +} + +int socket_connected(int s) +{ + struct sockaddr_in sa; + socklen_t dummy; + char ch; + int r; + + dummy = sizeof sa; + if (getpeername(s,(struct sockaddr *) &sa,&dummy) == -1) { + r = read(s,&ch,1); /* sets errno */ + return 0; + } + return 1; +} |