~ubuntu-branches/ubuntu/raring/simutrans/raring-proposed

« back to all changes in this revision

Viewing changes to dataobj/network_address.cc

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2011-11-03 19:59:02 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20111103195902-uopgwf488mfctb75
Tags: 111.0-1
* New upstream release.
* debian/rules: Update get-orig-source target for new upstream release.
* Use xz compression for source and binary packages.
* Use override_* targets to simplify debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "network_address.h"
 
2
#include "network_packet.h"
 
3
 
 
4
#include <stdlib.h>
 
5
#include <string.h>
 
6
 
 
7
net_address_t::net_address_t(const char *text)
 
8
{
 
9
        uint32 offset = 0;
 
10
        ip = 0;
 
11
        mask = 0;
 
12
        for(sint8 j=24; j>=0; j-=8) {
 
13
                uint32 n = atoi(text);
 
14
                ip   |= (n & 0xff) << j;
 
15
                mask |= 0xff << j;
 
16
                text = strchr(text+offset, '.');
 
17
                if (text) {
 
18
                        text++;
 
19
                }
 
20
                else {
 
21
                        break;
 
22
                }
 
23
        }
 
24
 
 
25
}
 
26
 
 
27
void net_address_t::rdwr(packet_t *packet)
 
28
{
 
29
        packet->rdwr_long(ip);
 
30
        packet->rdwr_long(mask);
 
31
}
 
32
 
 
33
void address_list_t::rdwr(packet_t *packet)
 
34
{
 
35
        uint32 count = get_count();
 
36
        packet->rdwr_long(count);
 
37
        for(uint32 i=0; i<count; i++) {
 
38
                if (packet->is_loading()) {
 
39
                        append(net_address_t());
 
40
                }
 
41
                (*this)[i].rdwr(packet);
 
42
        }
 
43
}