Bind: Socket operation on non-socket. UNIX Sockets

While the Socket itself is initialized, Binding Socket refused to bind returning -1 (socket operation on non-socket). Socket code:

#include "Socket.hpp"

Network::Socket::Socket(int domain, int service, int protocol, int port, unsigned long interface) {
    // Defining address structure
    address.sin_family = domain;
    address.sin_port = htons(port);
    address.sin_addr.s_addr = htonl(interface);

    // Establishing connection
    // Establishing socket
    int sock = socket(domain, service, protocol);
    int reuse = 1;
    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse));
    setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (const char*)&reuse, sizeof(reuse));
    std::cout << "Testing Socket" << std::endl;
    test_connection(sock);
}

// Test the connection TODO: maybe change this
void Network::Socket::test_connection(int to_test) {
    std::cout << "in test connection " << to_test << std::endl;
    if (to_test < 0) {
        perror("Connection failed");
        exit(EXIT_FAILURE);
    }
}

// Getters
struct sockaddr_in Network::Socket::get_address() {
    return address;
}

int Network::Socket::get_sock() {
    return sock;
}

Binding Socket code:

#include "BindingSocket.hpp"

// Constructor
Network::BindingSocket::BindingSocket(int domain, int service, int protocol, int port, unsigned long interface) : Socket(domain, service, protocol, port, interface) {
    connect_to_network(get_sock(), get_address());
    std::cout << "Testing BindingSocket " << std::endl; 
    test_connection(binding);
};

// Definition of connect_to network
void Network::BindingSocket::connect_to_network(int sock, struct sockaddr_in address) {
    binding = bind(sock, (struct sockaddr *)&address, sizeof(address));
}

Here’s the Server initializer (to see what I actually put into socket when initialized):

#include "TestServer.hpp"
Network::TestServer::TestServer() : SimpleServer(AF_INET, SOCK_STREAM, 0, 80, INADDR_ANY, 10) {
    launch();
}

// Accepts the connection
void Network::TestServer::accepter() {
    struct sockaddr_in address = get_socket()->get_address();
    int addrlen = sizeof(address);
    new_socket = accept(get_socket()->get_sock(), (struct sockaddr *)&address, (socklen_t *)&addrlen);
    read(new_socket, buffer, 3000); // should store the request in the buffer
}

// Handles the connection
void Network::TestServer::handler() {
    std::cout << buffer << std::endl;
}

// Responds to the connection
void Network::TestServer::responder() {
    char *hello_msg = "Hello from server";
    write(new_socket, hello_msg, sizeof(hello_msg) - 1); // Could not figure out a workaround, predefined function requires const void *__buf as well as size_t __n, although they are deprecated (gcc will give a warning, ignore it)
    close(new_socket);
}

void Network::TestServer::launch() {
    while(true) {
        std::cout << "IDLE" << std::endl;
        accepter();
        handler();
        responder();
        std::cout << "COMPLETED" << std::endl;
    }
}

I am very confused as to why this doesn’t work.

After googling the issue I tried to reset the port and address (as can be seen in the Socket.cpp), but it didn’t work. Also two other socket types do not work, not only Binding: Listening and Connecting sockets. I am guessing that the problem has the same root for all three but can’t find it myself. All show the same issue: socket operation on non-socket. Please, help!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật