Added close() method to stream classes.
[sockstream.git] / src / service.cpp
1 /**************************************************************************
2 **  (c) Copyright 2012, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : service.cpp
7 **      SYSTEM NAME    : Network and socket classes
8 **      VERSION NUMBER : 0.1
9 **
10 **  DESCRIPTION      :  Service class implementation
11 **
12 **  EXPORTED OBJECTS : class Service
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Mar 02, 2012
20 **      LAST UPDATE     : Mar 07, 2012
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 #include "service.h"
25
26
27 /*=========================================================================
28 **  NAME           : Service::FindAddress
29 **  SYNOPSIS       :
30 **  PARAMETERS     :
31 **  RETURN VALUE   : List of port numbers
32 **
33 **  DESCRIPTION    : Find all ports given the service name.
34 **
35 **  VARS USED      :
36 **  VARS CHANGED   :
37 **  FUNCTIONS USED :
38 **  SEE ALSO       :
39 **  LAST MODIFIED  : Mar 05, 2012
40 **=========================================================================
41 */
42
43 std::list<Port> Service::FindAddress()
44 {
45    struct addrinfo hints;
46    struct addrinfo *res, *rp;
47
48    hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
49    hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
50    hints.ai_flags = 0;
51    hints.ai_protocol = 0;          /* Any protocol */
52    hints.ai_canonname = NULL;
53    hints.ai_addr = NULL;
54    hints.ai_next = NULL;
55
56    int error = getaddrinfo(NULL, name, NULL, &res);
57
58    ports.clear();
59    for (rp = res; rp != NULL; rp = rp->ai_next)
60    {
61       struct sockaddr_in *sa;
62       sa = (struct sockaddr_in *)rp->ai_addr;
63
64       Port p(sa->sin_port, rp->ai_socktype);
65       ports.push_back(p);
66    }
67
68    freeaddrinfo(res);
69
70    return ports;
71 }
72