<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008 <NAME>.
#
# Author: <NAME> <<EMAIL> at <EMAIL> dot <EMAIL>>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

import sys
from socket import *

import umpa.utils
from umpa.utils import UMPAException

class Socket(object):
    """To send built packets your need to create a socket.
    You can use socket module from Python Standard Library directly
    but it's recommended to use this class instead.
    That is because there is some other features, and for some security issues.
    """
    def __init__(self):
        """This is a default constructor for Socket's class.
        Just use it in any doubts.
        """
        # XXX: if non-root EUID, then exception is raised
        # TODO: before raising UMPAException, we can try
        # to switch EUID into root and recall socket()
        try:
            self._sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
            # dropping root-priviliges
            utils.security.drop_priviliges()
        except error, msg:
            raise UMPAException(msg)
        # to build own headers of IP
        self._sock.setsockopt(IPPROTO_IP, IP_HDRINCL, 1)

    def send(self, *packets):
        """Sending your packets"""

        for packet in packets:
            # XXX: this connects to a remote socket, so destination address has to be known.
            # the better solution would be to use ARP (the lowest software layer from OSI).
            # it will be implemented when ARP protocol will be implemented ;)
            # so now we have to parse the packet for destination address
            dst_addr = self._get_address(packet)
            self._sock.sendto(packet.get_raw(), (dst_addr,0) )

    def _get_address(self, packet):
        """Because of ARP issue (described in send() method,
        we have to parse packets for destination addresses.
        """
        print "Not implemented yet."
        return False<commit_msg>Bug fixing in sockets.py<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2008 <NAME>.
#
# Author: <NAME> <<EMAIL> at gmail dot com>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

import sys
from socket import *

import umpa.utils.security
from umpa.utils import UMPAException

class Socket(object):
    """To send built packets your need to create a socket.
    You can use socket module from Python Standard Library directly
    but it's recommended to use this class instead.
    That is because there is some other features, and for some security issues.
    """
    def __init__(self):
        """This is a default constructor for Socket's class.
        Just use it in any doubts.
        """
        # XXX: if non-root EUID, then exception is raised
        # TODO: before raising UMPAException, we can try
        # to switch EUID into root and recall socket()
        try:
            self._sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
            # dropping root-priviliges
            umpa.utils.security.drop_priviliges()
        except error, msg:
            raise UMPAException(msg)
        # to build own headers of IP
        self._sock.setsockopt(IPPROTO_IP, IP_HDRINCL, 1)

    def send(self, *packets):
        """Sending your packets"""

        for packet in packets:
            # XXX: this connects to a remote socket, so destination address has to be known.
            # the better solution would be to use ARP (the lowest software layer from OSI).
            # it will be implemented when ARP protocol will be implemented ;)
            # so now we have to parse the packet for destination address
            dst_addr = self._get_address(packet)
            self._sock.sendto(packet.get_raw(), (dst_addr,0) )

    def _get_address(self, packet):
        """Because of ARP issue (described in send() method,
        we have to parse packets for destination addresses.
        """
        print "Not implemented yet."
        return False
{'fraction_non_alphanumeric': 0.07141518275538894, 'fraction_numerical': 0.008622305529522024, 'mean_word_length': 2.73407977606718, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '715017', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1392, 'n_words': 670}