Created
December 5, 2017 12:58
-
-
Save froland/0af9c1ddbbc66fd3bd26b1974951a8a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <netinet/in.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#define _exit_on_error() { fprintf(stderr,"error exit on line %d\n",__LINE__); exit(-1); } | |
int main(int argc, char *argv[]) | |
{ | |
int sock; | |
struct sockaddr_in adresse; | |
char hostname[100]="mars01"; | |
gethostname(hostname,100); | |
if( (sock = socket(AF_INET,SOCK_STREAM,0) ) == -1) | |
_exit_on_error(); | |
adresse.sin_family = AF_INET; | |
adresse.sin_port = htons(6969); | |
adresse.sin_addr.s_addr=inet_addr("10.107.45.51"); | |
if(connect(sock, (struct sockaddr *) & adresse, sizeof(struct sockaddr_in))) | |
_exit_on_error(); | |
if(write(sock,hostname,strlen(hostname)+1)==-1) | |
_exit_on_error(); | |
if(close(sock)==-1) | |
_exit_on_error(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment