Created
April 5, 2012 23:04
-
-
Save alesplin/2314886 to your computer and use it in GitHub Desktop.
Failing the wrong way (this is an ugly hack)
This file contains hidden or 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
/* | |
* test program to work on a configuration fix for T.connect 15 | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <arpa/inet.h> | |
#include <sys/time.h> | |
#include <time.h> | |
#include <sys/types.h> | |
int | |
main(int argc, const char *argv[]) | |
{ | |
int s; | |
int s2; | |
struct sockaddr_in sin5; | |
char *bogusAddr = "1.0.0.0"; | |
char *myAddr = "/*your_ip_here*/"; | |
errno = 0; | |
sin5.sin_family = AF_INET; | |
sin5.sin_addr.s_addr = inet_addr(myAddr); | |
sin5.sin_port = htons((getpid()% 5000) + 1111); | |
printf("Create test sockaddr_in: address = %s, port = %d\n", | |
myAddr, ntohs(sin5.sin_port)); | |
if (errno) { | |
printf("ERROR: %d: '%s'\n",errno,strerror(errno)); | |
return 1; | |
} | |
s = socket(AF_INET, SOCK_STREAM, 0); | |
if (errno) { | |
printf("ERROR: %d: '%s'\n",errno,strerror(errno)); | |
return 1; | |
} | |
/* try connecting to our bogus address */ | |
printf("Change of address--test sockaddr_in: address = %s, port = %d\n", | |
bogusAddr, ntohs(sin5.sin_port)); | |
sin5.sin_addr.s_addr = inet_addr(bogusAddr); | |
s2 = connect(s, (struct sockaddr *) &sin5, sizeof(sin5)); | |
if (s2 != -1) { | |
printf("That shouldn't have worked...\n"); | |
return 1; | |
} | |
if (errno != ENETUNREACH) { | |
printf("ERROR: connect call failed incorrectly, errno was %d: '%s' should have been ENETUNREACH\n", errno,strerror(errno)); | |
return 1; | |
} | |
else if (errno == ENETUNREACH) { | |
printf("yay!\n"); | |
} | |
return errno; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment