Created
September 27, 2011 09:53
-
-
Save rwoeber/1244712 to your computer and use it in GitHub Desktop.
Rest Airport (DSL) Connection (wait 5sec to get new IP)
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
| #include <stdio.h> | |
| #include <sys/socket.h> | |
| #include <sys/types.h> | |
| #include <netinet/in.h> | |
| #include <netdb.h> | |
| #include <arpa/inet.h> | |
| #include <unistd.h> | |
| int main (int argc, const char * argv[]) { | |
| // insert code here... | |
| int sd; | |
| int ret; | |
| struct hostent *host; | |
| struct sockaddr_in server; | |
| sd = socket(AF_INET, SOCK_DGRAM, 0); | |
| if (sd == -1) { | |
| printf("socket failed\n"); | |
| } | |
| server.sin_addr.s_addr = inet_addr(argv[1]); | |
| server.sin_port = htons(192); | |
| server.sin_family = AF_INET; | |
| if (connect(sd, &server, sizeof(server)) == -1) { | |
| printf("connect failed\n"); | |
| } | |
| char buffer[116]; // from sniffs | |
| int i; | |
| for (i = 1; i <116; i++) { | |
| buffer[i] = 0; | |
| } | |
| buffer[0] = (char)0x06; // disconnect from S. Sexton - thanks! | |
| if ((ret = send(sd, buffer, sizeof(buffer), 0)) == -1) { | |
| printf("send failed\n"); | |
| } | |
| printf("Disconnected...\n"); | |
| sleep(5); | |
| buffer[0] = (short)0x07; // connect from S. Sexton - thanks! | |
| if ((ret = send(sd, buffer, sizeof(buffer), 0)) == -1) { | |
| printf("send failed\n"); | |
| } | |
| printf("Reconnected...\n"); | |
| close(sd); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment