00001 /***************************************************************************** 00002 * Copyright 2005 Daniel Ferullo * 00003 * * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); * 00005 * you may not use this file except in compliance with the License. * 00006 * You may obtain a copy of the License at * 00007 * * 00008 * http://www.apache.org/licenses/LICENSE-2.0 * 00009 * * 00010 * Unless required by applicable law or agreed to in writing, software * 00011 * distributed under the License is distributed on an "AS IS" BASIS, * 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00013 * See the License for the specific language governing permissions and * 00014 * limitations under the License. * 00015 * * 00016 *****************************************************************************/ 00017 00018 /** 00019 * @file nethelp.h 00020 * @author Daniel Ferullo (ferullo@cmu.edu) 00021 * 00022 * @brief provides prototypes for basic helpful network functions 00023 */ 00024 00025 #ifndef __NETHELP_H__ 00026 #define __NETHELP_H__ 00027 00028 #include "def.h" 00029 #include "errorcodes.h" 00030 00031 /** 00032 * @brief resolves a hostname or IP to a 32bit IP number 00033 * 00034 * @param ip_or_name the hostname or IP as a string 00035 * @param ip the IP as a 32bit number 00036 */ 00037 errorcode resolveIP(char *ip_or_name, ip_t *ip); 00038 00039 /** 00040 * @brief binds a socket 00041 * 00042 * @param port_to_bind the desired port 00043 * @param sd a pointer to an int to fill in with the socket descriptor for the 00044 * bound socket, if successful. On error the value is undefined. 00045 * 00046 * @return SUCCESS, errorcode on failure 00047 */ 00048 errorcode bindSocket(port_t port_to_bind, sock_t *sd); 00049 00050 /** 00051 * @brief creates a TCP connection 00052 * 00053 * @param ip the network byte order 32 bit ip address to connect to 00054 * @param port the port to connect to 00055 * @param sd a pointer to a sd to fill in with the connection sd (value 00056 * undefined on error) If the socket descriptor is greater than zero 00057 * then the current socket descriptor will be used, otherwise a new one 00058 * will be created. 00059 * 00060 * @return SUCCESS, errorcode on failure 00061 */ 00062 errorcode tcp_connect(ip_t ip, port_t port, sock_t *sd); 00063 00064 #endif /* __NETHELP_H__ */ 00065