![]() |
| | #1 |
| Registered User Join Date: May 2007 Location: Berkeley, CA
Posts: 140
| Why create a wrapper fo getaddrinfo() Code: struct addrinto *
host_serv(const char *host, const char *serv, int family, int socktype)
{
int n;
struct addrinfo hints, *res;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_CANONNAME;
hints.ai_famility = family;
hints.ai_socktype = socktype;
if( n = getaddrinfo(host, serv, &hints, &res)) !=0)
return (NULL);
return (res);
}
Code: struct addrinfo *ai; ai = Host_serv(host, NULL, 0, 0); Code: struct addrinfo hints, *res;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_CANONNAME;
hints.ai_famility = family;
hints.ai_socktype = socktype;
if( n = getaddrinfo(host, serv, &hints, &res) !=0)
return (NULL);
Last edited by Overworked_PhD; 11-09-2007 at 08:50 PM. |
| Overworked_PhD is offline | |
| | #2 |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| If I ask myself that question, the answer would be: convenience. I'd rather call an easy function with a few params and get the data I require than fill out a troublesome struct and pass along. It also makes the code cleaner and more structurized, if you ask me. |
| Elysia is offline | |
| | #3 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,689
| > Why not just call getaddrinfo() directly in main() like Why write functions at all? The point would be to keep main from becoming a massive bloated function which is impossible to maintain. Even if it has only a dozen lines, and you only ever call it once from just one place, it's still an improvement. |
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Create new combo boxes based on items selected in preview combo box | RealityFusion | Windows Programming | 2 | 01-10-2007 09:50 AM |
| Can't create child windows | OnionKnight | Windows Programming | 2 | 11-30-2006 08:11 PM |
| How to create a DLL wrapper. | MindWorX | C Programming | 12 | 11-09-2006 02:52 PM |
| Need help to compile a GTK+ code with C++ sql wrapper | kingsz1 | C++ Programming | 2 | 10-12-2006 06:17 PM |
| Create a file from c++ program | Dan17 | C++ Programming | 2 | 05-08-2006 04:25 PM |