filename | src/ioutil.c |
changeset | 1077:136fc24d17ef |
prev | 1021:848db285a184 |
author | nkeynes |
date | Fri Mar 02 23:49:10 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Android WIP: * Rename gui_jni.c to gui_android.c - now quite android specific. * Implement generic EGL driver with very minimal Java wrapper * Run emulation in separate thread, and implement simple queue for inter-thread communication. * Add menu/action-bar items for start + reset |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/ioutil.c Fri Mar 02 23:49:10 2012 +10001.3 @@ -0,0 +1,54 @@1.4 +/**1.5 + * $Id$1.6 + *1.7 + * Network support functions1.8 + *1.9 + * Copyright (c) 2009 Nathan Keynes.1.10 + *1.11 + * This program is free software; you can redistribute it and/or modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.14 + * (at your option) any later version.1.15 + *1.16 + * This program is distributed in the hope that it will be useful,1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.19 + * GNU General Public License for more details.1.20 + */1.21 +1.22 +#include <string.h>1.23 +#include <unistd.h>1.24 +#include <sys/socket.h>1.25 +#include <netinet/in.h>1.26 +#include <arpa/inet.h>1.27 +#include <errno.h>1.28 +#include "ioutil.h"1.29 +1.30 +int io_create_server_socket(const char *interface, int port )1.31 +{1.32 + struct sockaddr_in sin;1.33 + int fd = socket(AF_INET, SOCK_STREAM, 0);1.34 + if( fd == -1 ) {1.35 + ERROR( "Failed to create TCP socket!" );1.36 + return -1;1.37 + }1.38 +1.39 + sin.sin_family = AF_INET;1.40 + sin.sin_addr.s_addr = 0;1.41 + sin.sin_port = htons(port);1.42 +1.43 + if( interface != NULL ) {1.44 + if( !inet_aton(interface, &sin.sin_addr) ) {1.45 + /* TODO: hostname lookup */1.46 + }1.47 + }1.48 +1.49 + if( bind( fd, (struct sockaddr *)&sin, sizeof(sin) ) != 0 ||1.50 + listen(fd, 5) != 0 ) {1.51 + close(fd);1.52 + ERROR( "Failed to bind port %d (%s)", port, strerror(errno) );1.53 + return -1;1.54 + }1.55 + return fd;1.56 +}1.57 +
.