geekbrains_network_programming/lesson_01/headers/address.h

56 lines
864 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* address.h
*
* Created on: 9 авг. 2022 г.
* Author: alexander
*/
#pragma once
#include <string.h>
#include <netinet/in.h>
namespace azh
{
class Address
{
private:
struct sockaddr_in _addr;
unsigned int _len;
public:
Address(unsigned short int family, unsigned int addr, unsigned short int port)
{
memset(&_addr, 0, sizeof(_addr));
_len = sizeof(_addr);
_addr.sin_family = family;
_addr.sin_addr.s_addr = addr;
_addr.sin_port = htons(port);
}
Address()
{
memset(&_addr, 0, sizeof(_addr));
_len = sizeof(_addr);
}
Address(Address &address)
{
_addr = address._addr;
_len = address._len;
}
unsigned int& size()
{
return _len;
}
struct sockaddr_in& operator*()
{
return _addr;
}
};
}